Two-level management of locks on shared resources

ABSTRACT

In a shared data system comprising one or more primary nodes and a plurality of secondary nodes, global lock manager on a primary node manages locks for shared resources by exchanging an abstract lock state with local lock managers on the secondary nodes. The abstract lock state includes a particular representation of all of the applications on the nodes that are requesting or are granted locks. The exchange of these particular lock states instead of individual requests improves performance by increasing concurrency and reducing off-machine communication. A global deadlock detector on a node detects and resolves global deadlocks, in conjunction with local deadlock detectors on the secondary nodes.

CROSS REFERENCE TO RELATED APPLICATIONS

The present application is a Continuation of, and claims priority to,U.S. Nonprovisional application Ser. No. 12/902,116, filed 11 Oct. 2010and entitled “Two Level Management of Locks on Shared Resources,” thedisclosure of which is incorporated herein by reference in its entirety.

BACKGROUND

1. Technical Field

The present invention relates generally to lock management, and moreparticularly to improving the performance of lock management for lockson shared resources.

2. Discussion of Related Art

Distributed data systems have long used “locking” as a means forensuring data integrity in a shared resource. At its most fundamentallevel, locking a resource is a technique used by an application toprevent its use by another application until the locking application isfinished with it, this locking technique being termed “exclusive”locking. In large systems, where data sharing and parallel transactionprocessing is the rule, it becomes increasingly important to insure thatlocking does not result in unnecessary delay of transactions. Indistributed and parallel systems, the various nodes typically rely onmessage passing for the sharing of information, and the processingoverhead associated with these messages for coordinating between largenumbers of nodes is significant. Thus, more efficient means ofconcurrency control are needed.

BRIEF SUMMARY

Accordingly, embodiments of the present invention include methods,computer program products and systems for managing locks on sharedresources in a distributed computer system comprising receiving at afirst primary node a first local lock state from a first secondary nodeof a plurality of secondary nodes, wherein the first local lock statecomprises a lock request for access to a shared resource by one or moretasks on the first secondary node, and a requested lock mode, at thefirst primary node, evaluating the first local lock state to determinewhether it is stale, and if yes, discarding the first local lock state,at the first primary node, if the first local lock state is not stale,granting the lock request if no conflicts exist, and otherwise addingthe first local lock state to a priority queue for the shared resourceand processing the priority queue for the shared resource, at the firstprimary node, generating a first global lock state in response to thefirst local lock state, wherein the first global lock state comprises aholdable lock mode that is granted to the first secondary node for theshared resource, and communicating the first global lock state from thefirst primary node to the first secondary node.

Further embodiments of the present invention include methods, computerprogram products and systems for managing locks on shared resources in adistributed computer system comprising a first primary node comprising afirst processor and a first memory having a plurality of priority queuesstored therein, a global deadlock detector comprising a second processorand a second memory having lock conflict information stored therein, anda plurality of secondary nodes each comprising a plurality of tasks,wherein the plurality of secondary nodes collectively comprises aplurality of shared resources, and wherein the plurality of priorityqueues comprises a priority queue for each shared resource in theplurality of shared resources. The first processor is configured withlogic to receive at the first primary node a first local lock state froma first secondary node of the plurality of secondary nodes, wherein thefirst local lock state comprises a lock request for access to a sharedresource in the plurality of shared resources by one or more tasks onthe first secondary node, and a requested lock mode, at the firstprimary node, evaluate the first local lock state to determine whetherit is stale, and if yes, discarding the first local lock state, at thefirst primary node, if the first local lock state is not stale, grantthe lock request if no conflicts exist, and otherwise add the firstlocal lock state to a priority queue for the shared resource andprocessing the priority queue for the shared resource, at the firstprimary node, generate a first global lock state in response to thefirst local lock state, wherein the first global lock state comprises aholdable lock mode that is granted to the first secondary node for theshared resource, and communicate the first global lock state from thefirst primary node to the first secondary node. The second processor isconfigured with logic to, at the global deadlock detector, receive andstore lock conflict information from two or more secondary nodes,wherein for each secondary node the lock conflict information compriseslocal lock waits and lock interests for one or more tasks on thesecondary node, at the global deadlock detector, detect a globaldeadlock using the received lock conflict information, wherein a globaldeadlock is a deadlock between tasks on two or more different secondarynodes, at the global deadlock detector, resolve the detected globaldeadlocks by selecting one of the deadlocked tasks as a victim, andcommunicate the victim selection from the global deadlock detector tothe secondary node where the selected victim task is located.

The above and still further features and advantages of embodiments ofthe present invention will become apparent upon consideration of thefollowing detailed description thereof, particularly when taken inconjunction with the accompanying drawings wherein like referencenumerals in the various figures are utilized to designate likecomponents.

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS

FIG. 1 is a block diagram illustrating an exemplary computer systemhaving a two-level locking system according to an embodiment of thepresent invention.

FIGS. 2, 3 and 4 are flowcharts depicting an exemplary method of a locallock manager generating a Local Lock Manager Abstract Lock State(LLM-ALS), according to an embodiment of the present invention.

FIG. 5 is a flowchart depicting an exemplary method of a local lockmanager processing a Global Lock Manager Abstract Lock State (GLM-ALS),according to an embodiment of the invention.

FIG. 6 is a flowchart depicting an exemplary method of a global lockmanager processing lock grant and release requests, according to anembodiment of the invention.

FIG. 7 is a flowchart depicting an exemplary method of a global lockmanager processing an existing lock, according to an embodiment of theinvention.

FIGS. 8, 9 and 10 are flowcharts depicting an exemplary method of aglobal lock manager processing a priority queue, according to anembodiment of the invention.

FIG. 11 is a flowchart depicting an exemplary method of a local deadlockdetector detecting deadlocks, according to an embodiment of theinvention.

FIG. 12 is a flowchart depicting an exemplary method of victim handlingby a local deadlock detector, according to an embodiment of theinvention.

FIG. 13 is a flowchart depicting an exemplary method of a globaldeadlock detector detecting and resolving global deadlocks, according toan embodiment of the invention.

DETAILED DESCRIPTION

Referring now to the Figures, an exemplary computer system 100 accordingto embodiments of the present invention is illustrated in FIG. 1. Theexemplary computer system 100 comprises one or more primary nodes 102and multiple secondary nodes 104, which are communicatively connected tothe primary node(s), for example via communication channels 110, 112.The system 100 may be a distributed computer system, cloud-based system,clustered database, or any other suitable multiple member system inwhich the present embodiments may be used. Each of the secondary nodes104 comprises a local lock manager (LLM) 20, storage 30, sharedresource(s) 40, and multiple applications 50, and at least one of theprimary nodes 102 comprises a global lock manager (GLM) 60 and storage70. Each of the secondary nodes 104 in the system also comprises a localdeadlock detector (LDD) 80. The system 100 further comprises a globaldeadlock detector (GDD) 90 and storage 75, which may be located on anysuitable node, for example on a central node 106 as shown in FIG. 1, ona primary node 102, or on one of the secondary nodes 104.

The local lock managers 20, the global lock manager 60, the localdeadlock detectors 80, and the global deadlock detector 90 may each beimplemented in the form of a processing system, or may be in the form ofsoftware. They can each be implemented by any quantity of conventionalor other computer systems or devices (e.g., computer terminals, personalcomputers (e.g., IBM-compatible PC, Apple Mac, tablet, laptop, netbook,etc.), etc.), cellular telephones/personal data assistants (e.g., PalmPre, Droid, iPhone, iPad, etc.), etc., and may include any commerciallyavailable operating system (e.g., AIX, Android, Linux, OSX, Sun Solaris,Unix, Windows, etc.) and any commercially available or custom software(e.g., browser software, communications software, word processingsoftware, etc.). These systems may include processors, memories (e.g.,RAM, cache, flash, ROM, solid-state, hard-disk, etc.), internal orexternal communications devices (e.g., modem, network adapter, etc.),I/O interfaces, output devices (e.g., displays, printers, etc.), andinput devices (e.g., physical keyboard, touch screen, mouse, trackpad,microphone for voice recognition, etc.).

Storage 30, storage 70 and storage 75 may be implemented by any quantityof any type of conventional or other databases (e.g., network,hierarchical, relational, object, etc.) or storage structures (e.g.,files, data structures, web-based storage, disk or other storage, etc.),on any conventional or other memory or storage device, and may bevolatile (e.g., RAM, cache, flash, etc.), or non-volatile (e.g. ROM,hard-disk, optical storage, etc.), and include any suitable storagecapacity.

Shared resources 40 may be any suitable computer-implemented resourcesuitable for sharing in a multiple member computer system. For example,the shared resources 40 may each be a computer system (e.g., a network,server, or server group), a hardware component (e.g., processors,memory, and storage devices such as hard disk drives or solid statedrives), software (e.g., operating systems, applications, databases, webservices, etc.), or a combination of both hardware and softwarecomponents. For example, the shared resources 40 may be a databasesystem or an application server. Or, for example, the shared resources40 may each be data objects, such as tables, indexes, stored queries,data files, log files, control files, and backup files, or data storageresources such as database clusters, tablespaces, memory spaces, orpages, or portions of these, e.g., a portion of a table such as a row(tuple), or a portion of a tablespace such as a page.

Applications 50 are any applications or portions thereof (e.g., a taskor thread) that access the shared resources, for example where theshared resources are tables, the applications may be any applicationthat accesses the tables, for example a database application or clientsuch as a DB2 client or part of an IBM Enterprise Content Managementsystem. Storage 70 on the primary node 102 stores lock information usedby the Global Lock Manager 60, for example, a lock table comprising theinterests of all secondary nodes in that lock, and user data relating tothe locks. Storage 75 on the central node 106 stores lock-relatedinformation needed by the Global Deadlock Detector 90 to resolve globaldeadlocks, e.g., lock wait information, lock interests, a global waitgraph, etc.

The computer system 100 may include additional servers, clients, andother devices not shown, and individual components of the system mayoccur either singly or in multiples, for example, there may be more thanone primary node 102 in the system. It is understood that any of thevarious components of the computer system 100 may be local to oneanother, or may be remote from and in communication with one or moreother components via any suitable means, for example a network such as aWAN, a LAN, Internet, Intranet, mobile wireless, etc. Communicationbetween the GLM 60 and the various LLMs 20 is depicted by communicationschannels 110, and communication between the GDD 90 and the various LDDs80 is depicted by communications channels 112. Communication between andamong the various nodes may be via any standard inter-machine protocol(e.g., TCP/IP, InfiniBand, etc.) if remote, or any standardintra-machine protocol (e.g., shared memory, pipes, etc.) if local.

The computer system comprises a two-level locking system, comprising oneor more global lock managers (GLM) 60 and a local lock manager (LLM) 20for each node of the system. Each LLM handles access to shared resourceson a per-application (equivalently, transaction) granularity, and theGLM controls access (locks) to shared resources on a per-membergranularity. More than one GLM may be used, because the operation ofmultiple GLMs allows redundancy of information (for high availability)as well as reducing overhead for each GLM. Not only does this improvescalability, because for n GLMs each have to perform 1/nth of the load,but it also allows the GLM to run on each member as opposed to having torun on a separate machine. The present embodiments also allow multiplestates in-flight between the LLMs and the GLM, asynchronouscommunication between the LLMs and GLM, and lock “pre-fetching”, all ofwhich reduce application wait time because asynchronous daemons canperform this work while the applications perform actual user activity.

Deadlocks are also handled in a two-level manner, and the system alsocomprises a global deadlock detector (GDD) 90, and a local lock detector(LDD) 80 for each node of the system. Each LDD handles local deadlocksamong applications on its local node, and the GDD handles globaldeadlocks among applications on different nodes. While the functionalityof the LLM and LDD may be combined into the same device in certainembodiments, in at least some embodiments the GLM and GDD necessarilyfunction independently of each other in order to achieve a desired highperformance.

A. Global Lock Management

The two-level lock manager of the present embodiments provides coherencyacross physical and/or logical nodes 104 (henceforth called “members”).The scheme is called “two-level” because there is a per-member LockManager, called the Local Lock Manager (or LLM), and a per-instance LockManager, called the Global Lock Manager (or GLM). On each member, theLLM grants locks to local applications, and if there is a conflict withanother member over a lock, the LLMs coordinate with the GLM, and theGLM resolves the global lock conflict and ensures proper coherency overthe whole cluster or computer system (i.e., no conflicting access to thesame resource) for any resources that are shared globally. For example,in a shared data environment two or more members may request a resource(lock) already held by another member or members. The process ofnotifying the latter member(s) that the lock is needed remotely iscalled a “reclaim.” The process of notifying and obtaining the lock forother members to use is called “reclaim processing.” In the presentembodiment, the GLMs are partitioned much like data is partitioned: lockrequests are hashed, for example based on lock name, or lock type,across multiple GLMs. Therefore, for each such hash class, each LLMalways communicates with the same GLM.

An arbitrary locking system can be defined in terms of “lock modes” thata resource can be locked with and their relationships, as well asoperations such as acquire, upgrade, downgrade, release, and lock. Therelationships between lock modes can be described by the followingmatrices:

-   -   compatible[ ][ ]: compatible[mode1][mode2] returns true if mode1        is compatible, i.e., can exist concurrently, with mode2.    -   dominates[ ][ ]: dominates[mode1][mode2] returns true if mode2        is at least as compatible as mode1.    -   LUB[ ][ ]: LUB[mode1][mode2] is the least upper bound (“LUB” or        “supremum”) of mode1 and mode2, that is, the mode which contains        mode1 and mode2 in its compatible set, but as few extraneous        modes as possible. LUB[mode1][mode2] is also called ‘group        mode’.    -   GLB[ ][ ]: GLB[mode1][mode2] is the greatest lower bound (“GLB”        or “infimum”) of mode1 and mode2.        As an example, some typical ‘lock modes’ could be: {NON, Share,        eXclusive, INtent, Universal}. A set of exemplary matrices        follows:

A  sample  compatibility  matrix $\begin{matrix}\; & \; & {NON} & {..S} & {..X} & {.{IN}} & {..U} \\\; & \; & \underset{\_}{\;} & \underset{\_}{\;} & \underset{\_}{\;} & \underset{\_}{\;} & \underset{\_}{\;} \\{NON} & | & T & T & T & T & T \\{..S} & | & T & T & F & T & T \\{..X} & | & T & F & F & T & F \\{.{IN}} & | & T & T & T & T & T \\{..U} & | & T & T & F & T & F\end{matrix}$ The  corresponding  dominates  matrix $\begin{matrix}\; & \; & {NON} & {..S} & {..X} & {.{IN}} & {..U} \\\; & \; & \underset{\_}{\;} & \underset{\_}{\;} & \underset{\_}{\;} & \underset{\_}{\;} & \underset{\_}{\;} \\{NON} & | & T & F & F & F & F \\{..S} & | & T & T & F & T & F \\{..X} & | & T & T & T & T & T \\{.{IN}} & | & T & F & F & T & F \\{..U} & | & T & T & F & T & T\end{matrix}$ The  resulting  LOB(supremum)  matrix $\begin{matrix}\; & \; & {NON} & {..S} & {..X} & {.{IN}} & {..U} \\\; & \; & \underset{\_}{\;} & \underset{\_}{\;} & \underset{\_}{\;} & \underset{\_}{\;} & \underset{\_}{\;} \\{NON} & | & {NON} & {..S} & {..X} & {.{IN}} & {..U} \\{..S} & | & {..S} & {..S} & {..X} & {..S} & {..U} \\{..X} & | & {..X} & {..X} & {..X} & {..X} & {..X} \\{.{IN}} & | & {.{IN}} & {..S} & {..X} & {.{IN}} & {..U} \\{..U} & | & {..U} & {..U} & {..X} & {..U} & {..X}\end{matrix}$ The  resulting  GLB(infimum)  matrix $\begin{matrix}\; & \; & {NON} & {..S} & {..X} & {.{IN}} & {..U} \\\; & \; & \underset{\_}{\;} & \underset{\_}{\;} & \underset{\_}{\;} & \underset{\_}{\;} & \underset{\_}{\;} \\{NON} & | & {NON} & {NON} & {NON} & {NON} & {NON} \\{..S} & | & {NON} & {..S} & {..S} & {.{IN}} & {..S} \\{..X} & | & {NON} & {..S} & {..X} & {.{IN}} & {..U} \\{.{IN}} & | & {NON} & {.{IN}} & {.{IN}} & {.{IN}} & {.{IN}} \\{..U} & | & {NON} & {..S} & {..U} & {.{IN}} & {..U}\end{matrix}$

In addition to “lock modes”, the present embodiments provide for storinguser data with each lock. User data is an arbitrary chunk of data, whichis stored per application on the LLM (e.g., in storage 30) and permember on the GLM (e.g., in a lock table in storage 70). Because of thisrestriction, user data must consist of an entity which can beamalgamated (for example, a bit field, or a pointer for an exclusivelock, where it is ensured that there is only one such lock held permember at a time).

Conventional lock managers are request driven: an application or amember makes a request to acquire/upgrade/downgrade/release a sharedresource in some mode. The complete state of the system is a sum totalof all the requests and grants in-flight, and furthermore, strictordering must be observed, i.e., if an application (1) requests a lock Xand then (2) releases it, it's imperative that the order of operationsbe (1) followed by (2). Because of this feature, request-based systemsare inherently serial. Furthermore, each request must be fully processedto properly reflect the state of the system.

In contrast, the present embodiments are state-based, and thus avoid thelimitations of serial processing and processing each request that arerequired by conventional systems. In the present embodiments, eachcommunication between the LLMs and the GLM(s) is a complete, bounded(fixed-sized) lock state, called the Abstract Lock State (ALS). Each ALSdescribes the complete state of the system, thus allowing parallelizedcommunication instead of serial, and avoiding the need to process eachrequest, which are the two main weaknesses of a request-based system.Generally, the “state of a lock” includes the “group mode” (the LUB ofall held modes); any user data held; and all holders and waiters of thelock. States are denoted by [ ] brackets in this document. The stateparadigm cuts down communication costs because multiple applications areexpressed in a single communication (request).

The state of the Local Lock Manager is the set of lists of allapplications on all members waiting for or holding locks. Each list isFIFO ordered on each LLM to prevent starvation, and is a priority queueto give more flexibility. Note that it is not trivial to order all thelists' waiters, because they could have come into the system at the sametime and their ordering is not clear. However, whenever the topcontender from each LLM makes a request to the GLM, the requests can beordered on the GLM. Therefore, we obtain an ordering of the topcontending waiters across all LLMs. The state as described is obviouslycomplete, but not practical to work with because it scales linearly withthe number of applications (and therefore also number of LLMs). Inparticular, each LLM's list could never be exchanged with the GLMbecause of its linear growth with the number of applications because itwould become a communication bottleneck. The present embodiments thusutilize a new kind of fixed-sized state which nevertheless is acomplete-enough representation of the system. Each LLM still contains afull applications list. This application list is then represented perlock as an Abstract Lock State, called the local lock state or LLM-ALS.

Each LLM-ALS comprises a number of fields, for example the exemplaryfields shown below, which are discussed in further detail below withreference to the Figures:

-   -   sequence_number—an incremental number assigned to each LLM-ALS;    -   sub_sequence_number—an incremental number assigned to each        response to a request;    -   Holdable—the group mode, e.g., the least upper bound (LUB) of        all held applications;    -   Confirmed Holdable—the most recent value of Holdable received        from the GLM;    -   Grantable—grantable mode used for reclaim;    -   Fair—the mode of the top contending waiter(s);    -   Fair_flags—flags used to invoke special handling;    -   Fair_priority—priority of Fair;    -   Concurrent—an extended Fair that allows several applications to        run concurrently;    -   Maximum—the LUB of all holders and waiters; and    -   User_Data—user data that needs to be stored for granted modes,        for example it may comprise:        -   Holdable_user_data—user data that needs to be stored for the            current group mode;        -   Fair_user_data—user data that needs to be stored if Fair is            granted;        -   Concurrent_user_data—user data that needs to be stored if            Concurrent is granted; and        -   Maximum_user_data—user data that needs to be stored if            Maximum is granted.

The GLM receives the LLM-ALSs from the individual LLMs, and for eachlock, stores the received LLM-ALSs in a priority queue, sorted by the“Fair_priority” LLM-ALS field. The GLM may store all of these priorityqueues (one for each lock) in a lock table stored in storage 70, forexample. The lock table may comprise, for each lock known to the GLM,the interests of all members in that lock, ordered in a priority queue.When a new LLM-ALS comes in for a particular lock, the GLM attempts togrant the requested lock if there are no conflicts, but if there areconflicts, the request is queued for processing in the respectivepriority queue, in FIFO order. Regardless, the GLM sends the followingresponse back to the LLM, which is again an amalgamated fixed-sizestate, called the global lock state or GLM-ALS:

-   -   sequence_number—the number of the LLM-ALS to which the GLM-ALS        is responding;    -   sub_sequence_number—an incremental number assigned to each        response to a request;    -   Holdable—holdable mode granted to this lock;    -   Grantable—grantable mode used for reclaim;    -   Output_flags—flags used to notify the LLM of any special        conditions;    -   Blocked_client_priority—the highest priority of a remote client        this member is blocking; and    -   Output_user_data—user data of holders, e.g., the sum total of        all holders' user data.

The present embodiments involve sending multiple states between the LLMand GLM and parallelizing the lock process. By construction of theLLM-ALS, Concurrent fields are a subset of Maximum, while Fair fieldsare a subset of Concurrent and therefore Maximum. Therefore, any newgrant for a given LLM-ALS is necessarily a more complete operation. Alsoby construction, any subsequently generated LLM-ALS is complete on itsown. By amalgamating the state of the LLM into one LLM-ALS, the presentembodiments create a many-to-one mapping, that is, one LLM-ALS canrepresent multiple situations. As an example, the state [H=NON F=S C=SMAX=S] can represent any of these situations:

Member 1 Member 1 Member 1 app1 wants S app1 wants S app1 wants S app2wants S app2 wants IN

This many-to-one mapping is very desirable because it allows the systemto detect “true” system changes easily. For instance:

Member 1

app1 wants S

will generate and send a state [H=NON F=S C=S MAX=S]. Assume theresponse to this state has not yet arrived. If app2 now comes in andasks for S, the system does not generate a new state: app2 can simplywait for app1's response to return to know whether S was granted or not.If app3 now comes in and asks for IN, again, no new state needs to begenerated. In general, if a new requester ask for a mode dominated byFair, no communication is necessary. Accordingly, the presentembodiments provide benefits including an ordered communication system,no communication of redundant data, avoiding of unnecessary releases,solving the total release problem, and making use of responses that arenot the most recent.

In the present embodiments, the LLMs allow lock owners to “stick” to anunused lock in anticipation of future use. These “sticky locks” avoidunnecessary release and re-grant (and the associated network and CPUoverhead). When such a lock is reclaimed by the GLM, the LLM employs anegotiation scheme to release the lock, by repeatedly negotiating withthe lock holder until the lock is released. Negotiation overhead isavoided by passing the lock reclaim information to the holder through a“handshake” that guarantees the lock's release.

1. The Local Lock Manager (LLM)

Referring now to FIGS. 2, 3 and 4, reference numerals 200 a, 200 b, and200 c generally designate flow charts depicting an exemplary method of alocal lock manager processing lock requests and generating an LLM-ALS,according to an embodiment of the invention. In step 202, the local lockmanager (LLM) receives a request for a lock from an application, and instep 204 determines if there is a local conflict with the request. Ifyes, then in step 206 the LLM waits until the local conflict isresolved, and then returns to step 204. If not, then in step 208 the LLMdetermines if the lock is under reclaim. A reclaim occurs when a lock isre-acquired from a remote member or members. If yes, then in step 210the LLM waits until the lock has been reclaimed and then returns to step208. If not, then in step 212 the LLM creates a current Abstract LockState (ALS), also called the Current_LLM-ALS.

Steps 204 through 210 improve concurrency and help avoid lock“ping-ponging” by not generating any new LLM-ALSs when there is a localconflict or a lock is under reclaim. Waiting until these situations haveresolved before expressing additional interest in a lock to the GLMimproves performance. Lock ping-ponging refers to a situation where alock is contended for by multiple applications on two or more members.After granting the lock to just one application from a member, the lockmanager stops granting to the other applications from this member andgrants to one application from another member. This results in agranting order such that only one application from a member is grantedat a time, and the lock moves back and forth (ping-ponging) between themembers, which is very inefficient because of the communication costeach “ping-pong” incurs.

A strictly fair (FIFO) granting policy can lead to lock ping-ponging.Consider the following example:

member M1 member M2 app1 wants lock 1 in X app2 wants lock 1 in X app3wants lock 1 in X app4 wants lock 1 in X app5 wants lock 1 in X app6wants lock 1 in X . . . . . .These lock requests might be issued in the following order: app1, app2,app3, app4, . . . , so a simple FIFO policy would produce this sequenceof events:

member M1 holds the lock in X mode, app1 is granted

member M2 requests X, GLM sends reclaim to member 1

app1 releases, M1 releases due to reclaim

GLM grants to M2 (with reclaim information), app2 is granted

app2 releases, M2 releases due to reclaim

GLM grants to M1 (with reclaim information), app3 is granted

app3 releases, M1 releases due to reclaim

GLM grants to M2 (with reclaim information), app4 is granted

app4 releases, M2 releases due to reclaim

GLM grants to M1 (with reclaim information), app5 is granted

. . .

I.e., the lock is being ping-ponged between M1 and M2. Note that eachreclaim and ping-pong are inter-machine trips. Therefore, above, foreach app granted, we perform off-machine communication twice.

The present embodiments reduce lock ping-ponging using a new conceptcalled a reclaim line. The reclaim line is drawn when a member firstlearns about a reclaim. Existing requests on the LLM at that time areconsidered before the line (or before reclaim), new requests receivedafter are considered after the line (or after reclaim). In the aboveexample, when M1 first learned about the reclaim, requests from app2,app4, app6 are already received, so they are considered as beforereclaim. LLM can grant to these applications, before releasing the lockto GLM. Similarly, by the time GLM grants the lock to M2, requests fromapp3, app5 are already received. M1 will only release the lock afterapp3 and app5 release the lock. The improved sequence of events is:

M1 holds the lock in X mode, app1 is granted

M2 requests X, GLM sends reclaim to M1

-   -   M1 establishes the reclaim line, app3, app5 are before reclaim

app1 releases, M1 grants to app3

app3 releases, M1 grants to app5

(during this time, app11, app13, app15 on M1 request X, they are afterreclaim)

app5 releases, M1 releases due to reclaim

GLM grants to M2 (with reclaim information),

-   -   M2 establishes the reclaim line, app2 is granted and app4, app6        are before reclaim

app2 releases, M1 grants to app4

app4 releases, M1 grants to app6

(during this time, app12, app14, app16 on M2 request X, they are afterreclaim)

app6 releases, M2 releases due to reclaim

GLM grants to M1

M1 grants to app11, app13, app15, before returning the lock to GLM

M2 grants to app12, app14, app16, before returning the lock to GLM

. . .

app3 releases, M1 releases due to reclaim

GLM grants to M2 (with reclaim information), app4 is granted

app4 releases, M2 releases due to reclaim

GLM grants to M1 (with reclaim information), app5 is granted

. . .

Steps 214 through 246 describe the generation of the Current_LLM-ALS. Instep 214 the LLM determines the value for the “Holdable” field, which isequal to “group mode.” The Holdable value can only be increased by theGLM, and can only be reduced by an LLM. The LLM reduces the Holdablevalue as a response to an application releasing a lock, committing, oras a response to a reclaim.

In step 216, the LLM sets the value of “Confirmed Holdable” to the mostrecent value of Holdable received from the GLM, and in step 218, the LLMdetermines the value of “Grantable.” In steps 220 through 226, the LLMdetermines “Fair”, which is a mode allowing at least one additionalapplication to run on the LLM. Typically Fair is the first (in FIFOorder) unsatisfied request but there are exceptions if the firstunsatisfied request conflicts with group mode or in a reclaim situation.In step 220 the LLM determines if the first unsatisfied requestconflicts with group mode, in which case there is no fair. A conflictmay occur, for example, in the following scenario:

M1: app1 granted S

M1: app2 granted S

M1: app3 waiting X

Fair on LLM M1 will not become X, and the LLM determines in step 222that there is no fair and then proceeds to step 228. If there is noconflict, then the LLM in step 224 determines if the first unsatisfiedrequest is marked “before reclaim” and the LLM is in a reclaimsituation. For example, consider the following scenario:

M1: app1 granted S

M2: app2 wants X; reclaim sent to M1

M1: app3 wants U; is NOT marked ‘before reclaim’

Fair on LLM M1 will not become U, and the LLM determines in step 222that there is no fair and then proceeds to step 228. If the request ismarked “before reclaim”, or if the LLM is not under reclaim, then theLLM in step 226 determines Fair to be the first unsatisfied request.

In steps 228 and 230, the LLM determines “Concurrent”, which is a modethat when granted gives highest concurrency to the LLM and does not skipany unsatisfied applications. For example:

M1: app1 wants X

M1: app2 wants S

M1: app3 wants S

M1: app4 wants S

Fair=X, and although it would seem that Concurrent should be S, thatwould lead to starvation of app1. The LLM determines Concurrent by firstin step 228 determining a compatible set of applications, i.e., acontiguous set of applications, following FIFO order, all of which arecompatible with each other. For granted applications, the granted modeis used to compute the set, for waiters, the requested mode is used, andfor converters, either is used. For example, for the preceding scenario,the compatible set is {X}. In step 230, the LLM sets Concurrent to bethe Least Upper Bound (LUB) of the compatible set, for example for thepreceding scenario, Concurrent=X, the LLM then proceeds to step 232.

The determination of the compatible set and Concurrent is illustrated byadditional exemplary scenarios:

Scenario 1: M1: app1 wants S The compatible set is {S, IN, U} M1: app2wants IN Concurrent = U M1: app3 wants U M1: app4 wants X Scenario 2:M1: app1 wants S The compatible set is {S, IN} M1: app2 wants NConcurrent = S M1: app3 wants X M1: app4 wants U Scenario 3: M1: app1converts from IN to S The compatible set is {S, U} M1: app2 convertsfrom IN to X Concurrent = U M1: app3 converts from IN to U Scenario 4:M1: app1 converts from IN to S The compatible set is {S} M1: app2converts from IN to X Concurrent = S M1: app3 wants U

In step 232, the LLM determines “Maximum”, which is the LUB (supremum)of all the held and wanted modes. It can be useful when there is nocontention on a particular lock, because the GLM can grant Maximum andno other trips to the GLM will then be necessary, as in the followingscenario, where Maximum=X which eventually allows all apps to run:

M1: app1 wants IN

M1: app2 wants S

M1: app3 wants X

In step 234, the LLM determines the “User_Data” for the LLM-ALS. Fair,Concurrent and Maximum all have user data fields associated with them.When a particular mode (Fair, Concurrent or Maximum) is granted, the GLMwill remember the corresponding user data. Typically, one would want thefields to be an aggregate, that is, Maximum_User_Data is an aggregate ofthe Concurrent_User_Data and Maximum_User_Data fields, andConcurrent_User_Data is an aggregate of the Concurrent_User_Data andFair_User_Data fields. A simple example would be a bit field, which istermed “attribute” in the following scenarios. For example:

M1: app1 wants S, attribute 0x1

M1: app2 wants IN

M1: app3 wants U, attribute 0x2

The resulting computation of User_Data is: Fair=S, Fair Attributes=0x1,Concurrent=U, Concurrent Attributes=0x3. Note that the Fair attributeswill actually be the set of anyone granted, or considered for grant, asin the following scenario:

M1: app1 granted S, attribute 0x1

M1: app2 granted S

M1: app3 granted U, attribute 0x2

M1: app4 wants S, attribute 0x4

Here, Fair LRB=app4, and Fair Attributes=0x1|0x2|0x4=0x7. The “Fair LRB”refers to the lock request block (LRB) that was selected as Fair.Concurrent attributes are similar, except that it is now a set of allgranted applications' attributes, Fair Attributes and the compatibleset's attributes, as illustrated by the following:

M1: app1 granted X

M1: app2 wants S

M1: app3 wants S, attribute 0x2

M1: app4 wants IN, attribute 0x1

M1: app5 wants U, attribute 0x4

M1: app6 wants X, attribute 0x8

When app1 releases, the LLM determines that Fair LRB=app2, but FairAttributes=0x2. The compatible set is {S, IN, U}, therefore ConcurrentAttributes are 0x2|(0x1|0x4)=0x7. MaximumAttributes=(0x2|0x1|0x4|0x8)=0xF. For any ALS, the set of concurrentattributes includes the set of Fair attributes, and the set of Fairattributes includes the set of Held attributes. Thus, the modes Maximum,Concurrent, Fair and Holdable may be considered subsets of each other incertain respects.

As another example of “User_Data”, we describe a “Retained Bit”, whichis a single bit field that can be used for the purpose of member crashrecovery. For example, some locks were only taken for read operations,and therefore it does not make sense to hold them throughout memberrecovery which could be a lengthy process. However, some locks weretaken for write operations, and these locks need to be held until thecorresponding applications have recovered (committed or rolled back). Aretained lock is a lock which the GLM will hold (retain) throughoutmember recovery and crash. Otherwise, the lock will be released. Each ofthe Fair, Concurrent and Maximum modes have a “retained” bit associatedwith them: retained bits then undergo the same accumulation as describedabove. This is illustrated, e.g.:

M1: app1 wants S

M1: app2 wants S, write lock

M1: app3 wants U

This scenario results in [Fair=S, Fair Retained bit ON, Concurrent=U,Concurrent Retained bit ON, Maximum=U. Maximum Retained bit ON]. Note inthis scenario that the lock will become retained on the GLM even thoughapp1 did not specify it to be. The alternative would be for app2 to notbecome granted and wait for app1 to release before the lock becomesretained, but this would seriously impact concurrency, hence in thisapproach an application may benefit from a lock being retained even ifit did not require it to be. In another example:

M1: app1 wants S

M1: app2 wants U, write lock

M1: app3 wants X

This scenario results in [Fair=S, Concurrent=U, Concurrent Retained bitON, Maximum=X, Maximum Retained bit ON]. For any ALS, Maximum must beretained if Concurrent is retained, Concurrent must be retained if Fairis retained, and Fair must be retained if Holdable is retained.

“User_Data” may also include priority information. For example, the LLMdetermines the priority (“Fair_Priority”) of the ALS, which is the FairLRBs' priority that is determined by its application, e.g., throughworkload steering or another scheme. The priority field is the highestpriority of all the LRBs considered as fair.

In step 236, the LLM determines if a non-FIFO lock is needed, forexample an upgrade that requires special handling at the GLM to avoidFIFO ordering. If yes, then in step 238 the LLM sets the “Non-FIFO” flagand then proceeds to step 240. If not, the LLM proceeds to step 240. Instep 240, the LLM determines if the newly generated ALS (theCurrent_LLM-ALS) is different from the most recent ALS (theLast_LLM-ALS) that this LLM sent to the GLM, because if it is notdifferent (i.e., the state of the LLM has not changed), then it isunnecessary to send a new ALS. If it is not different, then the LLMdiscards the newly generated ALS and ends process 200. If the new ALS isdifferent, then in step 242 the LLM increments the value of the“Sequence_Number” field, for example by incrementing the signed integervalue from the Last_LLM-ALS, and in step 244 resets the value of the“Sub_Sequence_Number” field to a starting integer value (e.g., zero).Then, in step 246, the LLM sends the Current_LLM-ALS to the Global LockManager (GLM) and process 200 ends.

Referring now to FIG. 5, reference numeral 300 generally designates aflow chart depicting an exemplary method of a local lock managerprocessing a global lock manager abstract lock state (GLM-ALS) receivedfrom a GLM, according to an embodiment of the invention. In step 305,the local lock manager (LLM) receives an Abstract Lock State from theGlobal Lock Manager (a GLM-ALS), either in response to an LLM-ALS thatwas previously sent, or as a notification GLM-ALS. A notification is anasynchronous channel especially designed for this purpose: a member Xmay be busy running an application, which has blocked a remote member Ydue to a lock conflict. When this is detected the GLM sends anotification reclaim to the LLM on Member X. Because Member X is busy itmay not be able to process the reclaim. Instead an asynchronous threadwill process the notification and act on it. Because the thread isdecoupled from regular transaction processing it is guaranteed that itcan always process the reclaim and allow the cluster to proceed. Notethat processing a reclaim does not necessarily mean releasing the lock,because an application on Member X may still be accessing data protectedby this lock. In this case, processing the reclaim could simply meanthat the LLM on Member X has updated its local lock state to reflect thenew conflicting lock request from another member.

In step 310 the LLM determines if the GLM-ALS is still valid, e.g., ifthe GLM-ALS is stale or outdated. If the received GLM-ALS is stale, thenthe LLM proceeds to step 315 and determines whether any portion orportions of the GLM-ALS may be used, if not, rejects the GLM-ALS in step320 and then ends process 300, and if yes, performs limited processingof the usable portions of the GLM-ALS in step 325 and then ends process300. If the GLM is not stale, then the LLM proceeds to step 330.

Step 310 helps avoid confusion that may arise because multiple lockstates (LLM-ALSs and GLM-ALSs) may be in-flight at a time, and the lockstates may be received in any order. Consider the following scenariowhere there may be multiple local lock states in-flight at the sametime:

Member 1

app1 holds S

app1 changes user_data [seq=2 H=S F=C=MAX=S]

app1 changes user_data [seq=3 H=S F=C=MAX=S]

Even if the GLM processes seq=2 and seq=3 in-order, the GLM's responsesmay arrive in a different order at the LLM, such that the LLM processesthe response with seq=3 first. As such, when the LLM later attempts toprocess the response with seq=2, it will be rejected as stale.

Similarly, the LLM may receive an ALS from the GLM that is not recent,and because of the mixing of upgrades and releases and the number ofstates in flight, it is not clear whether the GLM-ALS can be used. Forexample, consider the following scenario:

Member 1

app1 holds S [H=S]

app1 releases down to IN [seq=1 CH=S H=IN F=IN]

app1 upgrades to S [seq=2 CH=S H=IN F=S]

app1 releases the lock [seq=3 CH=S H=NON F=NON]

app2 wants IN [seq=4 H=NON F=IN]

If the seq=2 response arrives [seq=2 ss=1 CH=S H=S G=S] before the seq=3and seq=4 responses, is it safe for app2 to use it? In this scenario,the answer is no, because seq=3 may be processed by the GLM and is goingto release the lock. In general, the LLM can use the minimum of themodes that are still in flight to the GLM and come later in the sequence(because the GLM could always process such a request and release thelock). In addition, the Confirmed Holdable field allows older states tobe used, due to the fact that later releases will be ignored because ofit.

The present embodiments solve this problem, by preventing earlier statesfrom being processed once a later state has been processed, so that thesystem does not “go back in time.” In order to prevent earlier statesfrom being processed, each ALS may be numbered sequentially, forexample, the LLM Abstract Lock States may be numbered in the“Sequence_Number” field, using, e.g., a signed integer. For each LLM-ALSthere can be multiple responses (grants) from the GLM, so each GLMAbstract Lock State contains a “Sequence_Number” field indicating theLLM-ALS to which it is responding, and a “Sub_Sequence_Number” field bywhich the GLM Abstract Lock States are numbered using, e.g., a signedinteger. Whenever a new ALS is generated, the appropriate sequence andsub-sequence numbers are set. The LLM may then compare the“Sequence_Number” and “Sub_Sequence_Number” fields of the receivedGLM-ALS to the “Sequence_Number” and “Sub_Sequence_Number” fields of thelast GLM-ALS that was processed, in order to determine which was morerecent. For example, when signed integers are used the LLM may simplysubtract the Sequence_Number value of the last processed GLM-ALS (“seq1”) from the Sequence_Number value of the received GLM-ALS (“seq 2”),and test whether the result is greater than zero. If the result is lessthan zero, then the received GLM-ALS is older than the last-processedGLM-ALS, and if the result is greater than zero, then that means seq2 ismore recent than seq1, even in the case where seq2 has wrapped from avery large positive value to a very large negative value. If the resultis zero, then the LLM may compare the Sub_Sequence_Number fields of thereceived and last processed GLM-ALS to determine which is more recent,in a similar fashion as for the Sequence_Number fields. TheSequence_Number and Sub_Sequence_Number field values for the lastprocessed GLM-ALS may be stored in the LLM, for example in a place thatis not freed when a lock's metadata is freed, such as a locking hashtable.

As will be discussed in more detail later, the GLM also evaluatesreceived LLM-ALSs to determine whether they are stale in a similarfashion. Thus, it is understood that the GLM does not necessarilyrespond to every LLM-ALS that is sent, because some LLM-ALSs will bedetermined to be stale and will be discarded instead of being processed.

In step 330, the LLM determines if the GLM-ALS signals a reclaim, e.g.,by determining whether the value of the “Grantable” field of the GLM-ALSis not equal to the value of the “Holdable” field. The value of“Grantable” is the highest mode that can be held on the local member sothat it does not block a remote member waiting for a resource. If areclaim is not signaled, then the LLM proceeds to step 335 and processesthe GLM-ALS, thus, for example, receiving the requested lock, and thenthe process 300 ends. It a reclaim is signaled, then the LLM proceeds tohandle the reclaim in steps 340 through 360.

When a reclaim is received, the lock is released so that the remotewaiter may make progress, in order to reduce starvation. The presentembodiments are designed to reduce lock “ping-ponging”, which occurswhen two or more members repeatedly reclaim a lock from each other, andwhich is very expensive because each reclaim involves at least oneinter-member communications exchange. For example, consider thefollowing scenario:

Member 1: Member 2: app1 holds X app11 wants X app2 wants X app12 wantsX app3 wants X app13 wants XIf Member 1 and Member 2 were to release their locks immediately uponnotice of a reclaim, then in this scenario the lock would “ping-pong”because at least six inter-member communications would be required. Anaïve solution would be to hold the lock on Member 1 until all holdersand waiters on Member 1 are serviced, and then to release the lock to aremote member where the process is repeated, thus ensuring that remotemembers are not starved and reducing the number of inter-membercommunications to one. However, the naïve solution can cause Member 2 tobe starved by additional applications (e.g., app4, app5, . . . appN)arriving on Member 1 and being served prior to releasing the lock toMember 2. Also, in certain scenarios the naïve solution may result inconfusion about who should release the lock, for example in this secondscenario:

Member 1: Member 2: app1 holds X app11 holds IN app2 wants Z app12 wantsX app3 wants S app13 wants XIn the second scenario, if app12 arrives before app2, app12 will reclaimthe lock from Member 1. On Member 1, a line is drawn to include {app1,app2, app3} and the lock continues to be held in X. When app1 releases,app2 cannot be granted because it wants a higher mode, Z. Therefore, thelock is now reclaimed from Member 2. At this point it is not clear who,if anyone should yield the lock.

The present embodiments reduce lock ping-ponging and starvation riskswhile also removing confusion about lock yielding by utilizing aconceptual “reclaim line” that is drawn when a reclaim arrives on amember and which includes all holders and waiters on the member that aredominated by the currently held mode. The lock will be held until allapplications in the line are serviced, and then the lock is released andthe process repeats on the remote member(s). In the second scenarioabove, this results in the “reclaim line” being drawn at {app1}, whichis dominated by the currently held mode. Once app1 has finishedexecuting, the lock is released to Member 2, where a reclaim line isdrawn at {app11, app12, app13} when the reclaim from app2 arrives.App11, app12 and app13 then finish executing and Member 2 releases thelock to Member 1 so that app2 and app3 may finish executing. Thissolution has required only two reclaims and has minimized inter-membercommunication without risking starvation or confusion.

Thus, as shown in FIG. 5, when a reclaim arrives at the LLM, the LLMdraws a reclaim line in step 340 to include all holders and waiters onLLM that are dominated by the currently held mode, which are consideredto be “above the line” applications. In step 345 the LLM allows the“above the line” applications to finish executing, and then in step 350releases the lock to the GLM so that it can be granted to the remotemember requesting the reclaim. The process then repeats on the remotemember. In step 355, the LLM receives the lock after the remote memberhas used and released the lock to the GLM and it is re-granted back tothe LLM, and in step 360 the LLM allows any “below the line”applications that have subsequently requested the lock to finishexecuting. The process then ends.

The present embodiments thus favor concurrency while beingstarvation-free. Any Lock Manager should ideally be starvation free.That is, an application should always be able to obtain a lock aftersome finite amount of time. Present embodiments generally ensure this byserving out requests in FIFO order, both on the LLM and on the GLM.Because the GLM utilizes priority queues it is, of course, theoreticallypossible that a low priority request is starved by a never ending streamof high priority requests. In practice, however, the users of highpriority requests are infrequent events and, therefore, the starvationrule is not violated. The present embodiments also allow for a non-FIFOordering of states on the GLM, which can theoretically lead tostarvation. In practice, however, this would be limited to, e.g.,upgrading applications, a particular time limit, or a certain number ofrequests. Because at any point in time there is a finite number of suchapplications, they are guaranteed to complete and thus again cause nostarvation. The present embodiments exhibit improved concurrency over asimple FIFO because of the enhancements just mentioned. Additionally,avoiding ping-ponging helps avoid off-machine communications.

2. The Global Lock Manager (GLM)

Referring now to FIG. 6, reference numeral 400 generally designates aflow chart depicting an exemplary method of a global lock managerprocessing lock grant and release requests, according to an embodimentof the invention. In step 405, the global lock manager (GLM) receives anLLM-ALS from a local lock manager (“LLM A”) requesting a lock grant orrelease for a particular lock, and in step 410 searches for the lock ina lock table on the GLM. In step 415 the GLM determines if the lockexists in the table, and if not, in step 420 creates lock and cliententries in the lock table, and in step 425 grants the requested Maximumlock mode to the requesting LLM, and proceeds to step 445.

If the lock exists, then in step 430 the GLM processes the lock andcreates a client entry for the received lock request in the priorityqueue for this lock (or finds and uses an existing client entry in thequeue), as is further described with respect to FIG. 7. In step 435 theGLM determines if the lock has changed, and if yes, then in step 440 theGLM processes the priority queue, as is further described with respectto FIGS. 8-10. The client entry comprises the information for the locallock state received from the LLM (the LLM-ALS) as well as the globallock state created by the GLM (the GLM-ALS) in response to the LLM-ALS.The priority queue may also be sorted at this time, for example bymoving high priority client entries toward the top of the queue, andmoving lower priority client entries toward the bottom of the queue. TheGLM then proceeds to step 445.

In step 445 the GLM determines the value for “Blocked_client_priority”,which is the highest priority of a remote client that member LLM A isblocking, and in step 450 the GLM determines the “Output_user_data”,which is the user data of all client lock holders, e.g., the sum totalof all holders' user data. In step 455 the GLM may set any output flagsto notify the LLM of any special conditions. For example, a reclaim canarrive via a regular GLM-ALS, or as a “notification” GLM-ALS having aspecial output flag set. Then process 400 ends.

Referring now to FIG. 7, reference numeral 500 generally designates aflow chart depicting an exemplary method of a global lock managerprocessing an existing lock, according to an embodiment of theinvention. The depicted process 500 is an embodiment of step 430 ofprocess 400. In step 505, the GLM finds the client entry associated withthe lock request, and if an entry does not exist, creates one. In step510, the GLM determines if the lock request in the client entry is staleor outdated, for example by comparing the values of the Sequence_Numberand Sub_Sequence_Number of the local lock state in the client entryagainst the Sequence_Number and Sub_Sequence_Number of the last LLM-ALSprocessed. If the lock request is stale, the GLM proceeds to step 515and rejects the lock request LLM-ALS, and then ends the process 500, andif it is not stale, then the GLM proceeds to step 520.

In step 520, the GLM determines if the lock request is requesting adowngrade in the lock, and if yes proceeds to step 525 and then step530, and if no proceeds to step 530. In step 525, the GLM determines thevalue of “Holdable.” For a standard GLM-ALS sent in response to anLLM-ALS, Holdable is equal to the highest mode that can be granted(which may be none) and for a reclaim GLM-ALS, Holdable remains the sameas it was for the last GLM-ALS that was sent to the LLM under reclaimbut Grantable is reduced. The Holdable value can only be increased bythe GLM, and can only be reduced by an LLM. The GLM increases (orgrants) Holdable as a result of an LLM asking for Fair, Concurrentand/or Maximum modes.

In step 530, the GLM determines if the lock request is requesting anupgrade in the lock, and if no proceeds to step 535, where it incrementsthe value of the “Sub_Sequence_Number” field in the GLM-ALS, for exampleby incrementing the signed integer value from the last GLM-ALS sent inresponse to the same LLM. Then in step 540 the GLM sets the new lockstate for the LLM, and ends process 500 (thus returning to process 400at step 435 as previously described). If an upgrade is requested, thenthe GLM tries to grant the requested upgrade, in steps 545 through 575.

In step 545, the GLM determines if the LLM associated with the cliententry wants a Fair lock mode, and if not ends process 500. If yes, thenin step 550 the GLM grants the Fair lock mode if it is possible, e.g.,if it is compatible with both the Fair lock mode of all client entrieshaving a higher priority than this particular client entry and theholdable lock mode of all client entries in the priority queue for thislock. In step 555 the GLM determines if the Fair lock mode was grantedfor this client entry, and if not ends process 500. If yes, then in step560 the GLM determines if the LLM associated with the client entry wantsa Concurrent lock mode, and if its Concurrent lock mode is compatible,e.g., if no client entry is currently awaiting a Fair lock mode and therequested Concurrent lock mode is compatible with the holdable lock modeof all client entries in the priority queue for this lock. If yes, thenin step 565 the GLM grants the Concurrent lock mode, and if not, endsprocess 500. In step 570 the GLM determines if the LLM associated withthe client entry wants a Maximum lock mode, and if its Maximum lock modeis compatible with the Concurrent lock mode of all client entries in thepriority queue for this lock. If yes, then in step 575 the GLM grantsthe Maximum lock mode and then proceeds to steps 535 and 540, and ifnot, the GLM ends process 500.

Referring now to FIGS. 8, 9 and 10, reference numerals 600 a, 600 b and600 c generally designate a flow chart depicting an exemplary method ofa global lock manager processing a priority queue of client entries,according to an embodiment of the invention. The depicted process 500 isan embodiment of step 440 of process 400. In step 605, the GLMdetermines if the LLM associated with the client entry wants a Fair lockmode, if yes proceeds to step 610 and grants the Fair lock mode if it iscompatible with the holdable lock mode of all client entries in thepriority queue for this lock, and then proceeds to step 612, and if not,remembers that this grant failed and proceeds to step 612. In step 612,the GLM determines if all client entries have been checked to determineif they want Fair, if not, returns to step 605, and if yes, proceeds tostep 615. In step 615, the GLM determines if Fair lock mode has beengranted to all client entries that want Fair, if yes proceeds to step620 and if not proceeds to step 645.

In step 620 the GLM determines if the LLM associated with the cliententry wants a Concurrent lock mode, if yes proceeds to step 625 and ifnot proceeds to step 635. In step 625, the GLM determines if therequested Concurrent lock mode is compatible with the Fair and Holdablelock modes of all client entries in the priority queue for this lock. Ifyes, then in step 630 the GLM grants the Concurrent lock mode andproceeds to step 635, and if not, proceeds to step 645. In step 635, theGLM determines if the LLM associated with the client entry wants aMaximum lock mode, and if its Maximum lock mode is compatible with theConcurrent and Holdable lock modes of all client entries in the priorityqueue for this lock and if not, the GLM proceeds to step 642. If yes,then in step 640 the GLM grants the Maximum lock mode and then proceedsto step 642. In step 642, the GLM determines if all client entries havebeen checked to determine if they want Concurrent and/or Maximum lockmodes, if no returns to step 620 to process the next client entry, andif yes proceeds to step 645.

In step 645, the GLM determines if the client entry wants a “top-up”,e.g., was granted its Fair lock, wants Concurrent lock mode, and ifConcurrent lock mode is compatible with the holdable lock mode of allclient entries in the priority queue for this lock. If not, the GLMproceeds to step 652, and if yes, the GLM grants the Concurrent lockmode and then proceeds to step 652. In step 652, the GLM determines ifall client entries have been checked to determine if they want a “topup”, if no returns to step 645 to “top up” the next client, and if yesproceeds to step 655. In step 655, the GLM determines the new Grantablefor the client that will not block any higher priority waiters in thepriority queue, and in step 660 updates Grantable in the client entry ifthe new determined Grantable is different than the previous Grantablevalue for that client entry. In step 662, the GLM determines if allclient entries have been checked and their new Grantables determined, ifno returns to step 655 to process the next client entry, and if yesproceeds to step 665.

Steps 665 through 685 are performed for each changed client entry (grantor reclaim). In step 665, the GLM increments the value of the“Sub_Sequence_Number” field in the GLM-ALS, for example by incrementingthe signed integer value from the last GLM-ALS sent in response to thesame LLM. In step 670 the GLM determines the value for“Blocked_client_priority”, which is the highest priority of a remoteclient that is blocked by the current client entry, and in step 675 theGLM determines the “Output_user_data”, which is the user data of allclient lock holders, e.g., the sum total of all holders' user data. Instep 680 the GLM may set any output flags to notify the LLM of anyspecial conditions. For example, a reclaim can arrive via a regularGLM-ALS, or as a “notification” GLM-ALS having a special output flagset. In step 685, the GLM starts asynchronous sending of the GLM-ALSgranting or reclaiming a lock to the LLM associated with the cliententry. In step 690, the GLM determines if all changed client entrieshave been checked, if no returns to step 665, and if yes, ends process600 and returns to process 400 at step 445 as previously described.

As can be understood from the preceding description, process 600attempts to grant lock requests in priority order, where at eachpriority level, requests are granted in Fair-Concurrent-Maximum order,where Concurrent will only be considered if all Fair requests aresatisfied, and Maximum will only be considered if all Fair andConcurrent requests are satisfied. The exception to this rule is the“top up” policy (steps 645 and 650), in which, once a client has beengranted Fair lock mode, due to the cost of the communication notifyingit, the GLM “tops up” the client by granting Concurrent requestsoutstanding for that same client prior to some other client entry's Fairlock mode, if they do not conflict with “Holdable.” The “top up” policyalso improves concurrency.

An embodiment of the described methods 400, 500 and 600 is shown in thefollowing exemplary pseudo-code.

=======Process a Set Lock State request========== Hash the lock nameLatch the hash class Look up the look in the look table If no lockexists  Grant maximum (Since no one else is interested in the lock) else process_existing_lock( ) if the lock state changed (other than bycreating a new lock) (The lock state has changed if    the requesterreduced its holdable or the GLM increased its    holdable or reduced itsgrantable)  {   do_grants( ) (Grant / Reclaim processing)  }finish_update( ) Put the response to the Set Lock State in the responsebuffer. ===================================================process_existing_lock( ) {  Find the client entry for the requesting LLM(If it is there)  If client entry found   |    Validate request againstexisting client state (This includes the sequence number              check for stale requests)    If request not valid     {     generate reject response      return     }    else     {     Determine if this is a non FIFO request (This is a non FIFO requestif the “increase concurrency” flag             is set in the request andthe client does not currently hold its fair mode)      If this is a lockdowngrade (Client is reducing holdable in some way, does not need to bea release)       {        If confirmed holdable does not match actualholdable (Assume client has missed a grant in flight)         {         Set the requested holdable to the GLB of the existing holdableand the requested maximum, i.e.,           to the maximum of theexisting holdable and the requested maximum         }       }     }   } else (Client entry does not yet exist}   {    Allocate client entry andadd it to priority queue for this lock   }  /* At this point we have theclient entry either because we found it *  /* or have just created itand added it. */  // Check for downgrade or upgrade.  //  // NB: Mustcheck for downgrade before upgrade. Client could be doing a  // releaseby lowering holdable while at the same time indicating that it  // wantsit back by raising maximum, fair, or concurrent. It this is the  // casewe downgrade the clients holdable but leave it in the list as a  //waiter who is waiting for the lock in fair, concurrent, or maximum  //mode.  If this is a downgrade (Holdable is being reduced)   {    Reducethe holdable as requested    If this is an upgrade (Any of fair,concurrent, maximum are unsatisfied)     try_grant( )   }  else if thisis an upgrade (Any of fair, concurrent, maximum are unsatisfied)   {   try_grant( )   }  increment subsequence number  Set new lock state }=================================================== try_grant( ) {  ifclient wants fair   {    grant fair if the fair mode is compatible withthe fair modes of     all clients above this one and with all otherholdables   }  If we granted fair mode and no client is waiting for fairmode and this client    still wants something (concurrent or maximum)  {    If client wants concurrent and concurrent is compatible with allother holdables     grant concurrent    If client wants maximum andmaximum is compatible with all the other concurrents     grant maximum  } } At this point we have only changed the client entry of therequester. But since that resulted in a lock state change, we may beable to do additional grants and we may discover that we need to do areclaim because the requester become a waiter that should not beblocked. The first thing we attempt is grants. We try to grant fair toany client entry awaiting fair. As we go through this code, if we changethe lock state of a client entry we put it on a local list called thegrant list. do_grants( ) {  // Try to grant fair  loop through allclient entries from top to bottom (i.e., in priority order)  {   If thisclient wants fair    {     If its fair mode is compatible with all otherholders      {       Remember that we granted fair to at least oneclient       Grant fair      }     else      {       Failed to make agrant, remember that at least one fair not granted      }    }  }  If wegranted fair to everyone that wants it   {    loop through all cliententries from top to bottom (i.e., in priority order)    {     If clientwants concurrent      {       If concurrent is compatible with all otherholdables        grant concurrent       else // cannot grant concurrent       terminate the loop      }     If client wants maximum      {      If maximum is compatible with all other concurrents of all otherclient entries        grant maximum      }    }   }  If we grantedanything to this client   Put the client entry on the grant list  // Nowtop up the ones just granted fair  loop through all client entries fromtop to bottom (i.e., in priority order)  {   If we just granted fair tothis client and it wants concurrent    {     If the desired concurrentis compatible with all other holdables      grant concurrent    }  }  /*First find the fair mode of either the first waiter (no non FIFOwaiters  */  /* present) or of all the non FIFO waiters. This is the setfor whom a reclaim*/  /* will be issued. */  /* Having found the set forthe reclaim, then find all subsequent waiters */  /* whose fair mode iscompatible with the first set. Quit when we find */  /* the first onethat is not compatible with the set. This is the set */  /* for which areclaim will be issued. */  /* At the same time find the priority of thefirst blocked waiter. This */  /* will be used to tell client entriesthe priority of the first waiter */  /* they are blocking. Also rememberif any of the waiters are non FIFOs   */  // Now that the holdables (ifany) have been updated, go through the list  // again recalculating thegrantables. If any client's grantable changes  // put them on the grantlist if not already there.  loop through all client entries from top tobottom (i.e., in priority order)  {   Calculate a new grantable for thisclient entry such that its new grantable   will not block any of theabove described waiters on whose behalf we are   issuing reclaim   Ifthe new grantable is not the same as the old grantable    Put thisclient entry on the grant list if not already there   If this client'sblocked client priority has changed or if it    is blocking a non FIFOwaiter    {     Put this client entry on the grant list if not alreadythere    }  }  loop through each client entry on the grant list (This isthe list of all   client entries for whom grant / reclaim is to be done  {    Increment the sub_sequence_number    finish_update( )    Send thegrant / reclaim asynchronously with the following properties:     1. Noone waits for the send to happen     2. In the rare case that the sendscan't keep pace with the state changes,      a. the pending sends don'tinterface in any way with the state changes happening,      b. When asend does happen, it sends the latest state, whatever that might be   }} =================================================== finish_update( ) { Determine blocked client priority  Determine output user data  Setoutput flags }

The present embodiment may also provide an optimized “upgrade withrelease” request. This request carries with it two types of actions: (1)if the upgrade is successful, it behaves like a normal request. (2) ifthe upgrade fails, the lock is released or downgraded. This can simplybe done by specifying: H=<release mode> F=<want mode>. In a requestdriven Lock Manager implementation, two requests would be needed tofulfill the requirement: a downgrade and an upgrade. There are twopossible orderings:

-   -   (A) First downgrade, then upgrade. This consists of 2 requests        and furthermore, even if the upgrade succeeds, no assumption can        be made about the validity (coherency) of the data, due to the        fact a downgrade was done first.    -   (B) First upgrade; if it fails, release. Here the data remains        coherent, but this scheme is poor for concurrency, since it can        easily introduce deadlocks, as per the following scenario:        -   app1 holds S, upgrade with release to X        -   app2 holds S, upgrade with release to X            Here, app1 is deadlocked with app2. The state-based scheme            of the present embodiments avoids both (A) and (B).

The present embodiments also provide an optimized “retrieve user dataand conflict information” (TryInstant) request. This request is a formof an “instant” request whose most important feature is that the stateof the system is not mutated: if the lock could be granted. SUCCESS isreturned, but the state of the system is unchanged. If the lock couldnot be granted, FAILURE is returned and again the state of the system isunchanged. Additionally, user attributes are returned. The usefulness ofthis type of request is to determine if there is conflict on a givenlock, in a given mode. If there is, the returned user data can giveimplicit information about the holders of the lock (for example, whethera certain operation is currently in progress). Note that without aTryInstant, this would need to be done with a request which—ifgranted—would then need cancelling (meaning communication cost).

In the present embodiments, normally all lock requests are handled in aFIFO order. As illustrated below this could be undesirable in theupgrade case:

M1: app1 holds S

M1: app2 wants X

M1: app1 wants to upgrade to X

In this example app2 is queued first, causing a deadlock between app1and app2. However, if app1 could be granted first, it would proceedallowing app2 to eventually finish as well. The present embodiments arevery flexible, and allow two kinds of list within each priority queue: aFIFO list, and an unordered, ahead-of-FIFO non-FIFO list.

Additionally, the present embodiments provide asynchronous lock release.In many cases the release of a lock can be done asynchronously—controlis returned to the caller, and the GLM is notified at a later time,either by an asynchronous process, or by remembering the change andsending it with a later request. The benefit of this is that the releaseis instantaneous.

The present embodiments provide numerous benefits and advantages overstandard concurrent systems, by reducing inter-member communications,which are generally the gating factor determining performance (definedhere as the time to obtain/release a resource). As has been describedpreviously, the present embodiments are able to keep inter-membercommunication to a bare minimum by:

-   -   Communication being state based, with each state being a        complete snapshot of a resource's holdings/requests;    -   Expressing the interest of multiple applications (transactions)        in each communication;    -   Allowing multiple in-flight communications between the LLM and        GLM and managing them efficiently;    -   Favoring concurrency while being starvation free;    -   Providing an efficient mechanism to obtain remotely held locks        and reducing lock ping-ponging;    -   FIFO and Non-FIFO ordering; and    -   Asynchronous lock release.

The two-level lock manager system also provides an unparalleled highavailability solution, in that if any member of the computer systemcrashes, only locks that are in-flight (on the wire) at the time arelost. All other locks are remembered, and crash recovery may proceed ina way far quicker than the conventional one-lock manager systems.

B. Global Deadlock Resolution

Deadlocks may occur in the lock management system of the presentembodiments, as in any distributed system. While it is theoreticallypossible to prevent or avoid deadlocks in a distributed system, it isusually cost-prohibitive to attempt because of the enormous amounts ofnetwork traffic and inter-member messages that would be required.Instead, the present embodiments focus on detecting and resolvingdeadlocks in a manner that does not create significant performanceproblems. In the present embodiments, each local deadlock detector (LDD)handles local deadlocks among applications on its local node, and theglobal deadlock detector (GDD) handles global deadlocks amongapplications on different nodes.

For example, on an individual member, local applications may bedeadlocked over a resource, and the local deadlock detector (LDD)detects and resolves these local deadlocks. Sometimes, however, a localapplication may be deadlocked with a remote application on anothermember, and the LDDs of the members are not able to resolve this globaldeadlock. This can occur, for example, in the following scenario:

-   -   App1 on Member 1 holds a lock (lock mode S) on resource r1 and        is requesting a lock (lock mode X) on resource r2    -   App22 on Member 2 holds a lock (lock mode S) on resource r2 and        is requesting a lock (lock mode X) on resource r1        Here, there is a global deadlock between App1 and App22, that        cannot be resolved by the LDDs of the members. Accordingly, the        LDDs send local lock wait and lock interests to the GDD, which        generates a remote lock wait between each waiter and each        reclaimed lock holder, and uses it to detect and resolve this        global deadlock, e.g., by choosing one of the waiters as a        victim that will release its lock request and allow the other        waiter to obtain the requested lock.

The GDD is able to resolve global deadlocks entirely independent of theGLM. This independence maintains the high performance of the two-levellocking system, because the GLM is able to handle its lock management ata higher level, i.e., member-to-member locks, instead of having tocollect and process information about individual applications and lockrequests on various members. In other words, the GLM is not required toknow what application on a member is requesting a lock—it only needs toknow what the situation is between a member requesting a lock and themember holding the lock. To involve the GLM in the deadlock processwould result in significant processing and network overhead at the GLM,thus obviating the performance benefits previously described. Therefore,the present embodiments provide for the GDD to detect and resolve globaldeadlocks without any information from the GLM. This global deadlockdetection scheme detects all local and global deadlocks.

Referring now to FIG. 11, reference numeral 700 generally designates aflow chart depicting an exemplary method of a local deadlock detectordetecting deadlocks, according to an embodiment of the invention. Thesesteps may be carried out by, e.g., each local deadlock detector (LDD) oneach member node 104 of the system 100. In step 705, the local deadlockdetector (LDD) monitors and collects local lock information about thelocal applications, in step 710 determines local lock waits based on thelocal lock wait information, and in step 715 uses the local lock waitsto build a local wait graph (also called a local wait-for graph or LWG).In step 720, the LDD detects local deadlock(s) in the local wait graph,e.g., cycles in the graph, and then in step 725 resolves thedeadlock(s), e.g., by selecting one or more local applications asvictims to be killed so that the deadlock is broken.

In step 730, the LDD determines if there is a local application waitingfor a lock request to be granted (an “unprocessed waiter app”). If not,the LDD returns to step 705 and continues to monitor local locks. Ifyes, then in step 735, the LDD determines if the waiter application onits member node has lock requests that are blocked by a remoteapplication, or if a waiter application has lock grants that areblocking a remote application and causing remote lock waits. If yes,then in step 740 the LDD generates lock interests, and then proceeds tostep 745. If not, then the LDD proceeds to step 745 and sends the lockwaits (from step 710) and any generated lock interests (collectively“lock conflict information”) to the Global Deadlock Detector (GDD), andthen returns to step 730 to check for other unprocessed local waiterapplications. The lock interests help identify remote lock waiters andremote lock waitees (a lock holder whose lock is reclaimed by the GLM inorder to satisfy an application running on a remote member).

For example, consider the following scenario:

For resource r1:

Member 1 holds S lock for Task1

Member 2 wants X lock for Task2

Member 3 wants X lock for Task3

Member 4 wants S lock for Task4

The lock held by Member 1 is under reclaim by the GLM

The LDD on Member 1 sends to GDD:

Task1 is a remote lock waitee (mode S); lock under reclaim

The LDD on Member 2 sends to GDD:

Task2 is a remote lock waiter (mode X)

The LDD on Member 3 sends to GDD:

Task3 is a remote lock waiter (mode X)

The LDD on Member 4 sends to GDD:

Task 4 is a remote lock waiter (mode S)

In the above example, after Task1 releases the lock, it would be grantedto Task2, Task3 and then Task4. This order is important because the lockrequests must be granted in the order the order they are received (Task4cannot be granted the lock even if it is compatible with the currentholder). Because the GLM is completely unaware and uninvolved in theglobal deadlock detection, the GDD cannot determine the direct lock waitrelationships between the waiters Task2, Task3, Task4. So, it is unableto build any global/remote lock wait edges involving two waiters.Instead, the GDD of the present embodiments uses an alternative approachof completely relying on lock wait edge between waiters and holders. Tocompensate for the missing lock wait edges between two waiters, itbuilds a global lock wait edge between every waiter and every reclaimedholder. In this example, global lock wait edges would be Task4→Task1,Task3→Task1, Task2→Task1. These edges are sufficient to break the anydeadlock that involves this lock.

Referring now to FIG. 12, reference numeral 800 generally designates aflow chart depicting an exemplary method of victim handling by a localdeadlock detector, according to an embodiment of the invention. Thesesteps may be carried out by, e.g., each local deadlock detector (LDD) oneach member node 104 of the system 100. In step 800, the local deadlockdetector (LDD) receives a deadlock resolution from the GDD, and in step820 determines whether the resolution kills a local application. Forexample, assume that Task2 is chosen as the victim in the scenarioabove. The LDD on Member 2 examines the deadlock resolution it hasreceived from the GDD, and in step 820 determines that its local taskTask2 is a victim, and then proceeds to step 830, where it determineswhether the wait for the victim (Task2) has changed or disappeared, inorder to protect from unnecessary killing of victims. If the wait haschanged or disappeared, then the LDD ends the victim handling process.If the wait has not changed or disappeared, then the LDD proceeds tostep 840 and kills the victim (which releases all locks held orrequested by the victim), and the process 800 ends. Another LDD, e.g.,the LDD on Member 3, in step 820 determines that the resolution does notkill the local application (Task3), and then the process 800 ends. Thedeadlock having been resolved, Member 3 will receive the lock and assignit to Task3.

Referring now to FIG. 13, reference numeral 900 generally designates aflowchart depicting an exemplary method of a global deadlock detectordetecting and resolving global deadlocks, according to an embodiment ofthe invention. In step 910, the GDD receives the lock conflictinformation (e.g., local lock waits and lock interests) from the LDDs inthe system, and e.g., stores this information in storage area 75, and instep 920, the GDD uses this received information to determine globallock waits between each waiter and each reclaimed lock holder (waitee).The GDD does not have other information, for example, the GDD is notaware of global lock request information, nor does it know the order ofthe global lock requests. Instead, the GDD relies on the local lockwaits and lock interests that it receives from the LDDs to determine thelock waits. For example, in the scenario above, the GDD only knows thatTask2, Task3 and Task4 are waiters, and that Member 1's lock is underreclaim by the GLM.

In step 930, the GDD uses the global lock waits to build a global waitgraph (also called a global wait-for graph or GWG), which may be, e.g.,stored in storage area 75, and in step 940 the GDD detects globaldeadlock(s) in the global wait graph, e.g., cycles in the graph, andthen in step 950 resolves the deadlock(s), e.g., by selecting one ormore applications as victims to be killed so that the deadlock isbroken. Typically, the victim or victim(s) are the waiters that requirethe least overhead to kill (rollback), but the GDD is permitted toselect a suboptimal victim. In step 960, the GDD notifies the LDDs ofresolved global deadlock(s), so that LDDs can kill the designatedvictim(s). Process 900 then ends.

As will be appreciated by one skilled in the art, aspects of the presentinvention may be embodied as a system, method or computer programproduct. Accordingly, aspects of the present invention may take the formof an entirety hardware embodiment, an entirely software embodiment(including firmware, resident software, micro-code, etc.) or anembodiment combining software and hardware aspects that may allgenerally be referred to herein as a “circuit,” “module” or “system.”Furthermore, aspects of the present invention may take the form of acomputer program product embodied in one or more computer readablemedium(s) having computer readable program code embodied thereon.

Any combination of one or more computer readable medium(s) may beutilized. The computer readable medium may be a computer readable signalmedium or a computer readable storage medium. A computer readable mediummay be, for example, but is not limited to, an electronic, magnetic,optical, electromagnetic, infrared, or semiconductor system, apparatus,or device, or any suitable combination of the foregoing. More specificexamples (a non-exhaustive list) of the computer readable storage mediumwould include the following: an electrical connection having one or morewires, a portable computer diskette, a hard disk, a solid state disk, arandom access memory (RAM), a read-only memory (ROM), an erasableprogrammable read-only memory (EPROM or Flash memory), an optical fiber,a portable compact disc read-only memory (CD-ROM), on optical storagedevice, a magnetic storage device, a phase change memory storage device,or any suitable combination of the foregoing. In the context of thisdocument, a computer readable storage medium may be any tangible mediumthat can contain, or store a program for use by or in connection with aninstruction execution system, apparatus, or device.

A computer readable signal medium may include a propagated data signalwith computer readable program code embodied therein, for example, inbaseband or as part of a carrier wave. Such a propagated signal may takeany of a variety of forms, including, but not limited to,electromagnetic, optical, or any suitable combination thereof. Acomputer readable signal medium may be any computer readable medium thatis not a computer readable storage medium and that can communicate,propagate, or transport a program for use by or in connection with aninstruction execution system, apparatus, or device. Program codeembodied on a computer readable medium may be transmitted using anyappropriate medium, including but not limited to wireless, wireline,optical fiber cable, RF, etc., or any suitable combination of theforegoing.

Computer program code for carrying out operations for aspects of thepresent invention may be written in any combination of one or moreprogramming languages, e.g., an object oriented programming languagesuch as Java, Smalltalk, C++ or the like, or a conventional proceduralprogramming language, such as the “C” programming language or similarprogramming languages. The program code may execute entirely on theuser's computer, partly on the user's computer, as a stand-alonesoftware package, partly on the user's computer and partly on a remotecomputer or entirely on the remote computer or server. In the latterscenario, the remote computer may be connected to the user's computerthrough any type of network, including a local area network (LAN) or awide area network (WAN), or the connection may be made to an externalcomputer (for example, through the Internet using an Internet ServiceProvider).

It is to be understood that the software for the computer systems of thepresent invention embodiments may be implemented in any desired computerlanguage and could be developed by one of ordinary skill in the computerarts based on the functional descriptions contained in the specificationand flow charts illustrated in the drawings. By way of example only, thesoftware may be implemented in the C#, C++, Python, Java, or PHPprogramming languages. Further, any references herein of softwareperforming various functions generally refer to computer systems orprocessors performing those functions under software control.

The computer systems of the present invention embodiments mayalternatively be implemented by any type of hardware and/or otherprocessing circuitry. The various functions of the computer systems maybe distributed in any manner among any quantity of software modules orunits, processing or computer systems and/or circuitry, where thecomputer or processing systems may be disposed locally or remotely ofeach other and communicate via any suitable communications medium (e.g.,LAN, WAN, Intranet, Internet, hardwire, modem connection, wireless,etc.).

Aspects of the present invention are described with reference toflowchart illustrations and/or block diagrams of methods, apparatus(systems) and computer program products according to embodiments of theinvention. It will be understood that each block of the flowchartillustrations and/or block diagrams, and combinations of blocks in theflowchart illustrations and/or block diagrams, can be implemented bycomputer program instructions. These computer program instructions maybe provided to a processor of a general purpose computer, specialpurpose computer, or other programmable data processing apparatus toproduce a machine, such that the instructions, which execute via theprocessor of the computer or other programmable data processingapparatus, create means for implementing the functions/acts specified inthe flowchart and/or block diagram block or blocks.

These computer program instructions may also be stored in a computerreadable medium that can direct a computer, other programmable dataprocessing apparatus, or other devices to function in a particularmanner, such that the instructions stored in the computer readablemedium produce an article of manufacture including instructions whichimplement the function/act specified in the flowchart and/or blockdiagram block or blocks. The computer program instructions may also beloaded onto a computer, other programmable data processing apparatus, orother devices to cause a series of operation steps to be performed onthe computer, other programmable apparatus or other devices to produce acomputer implemented process such that the instructions which execute onthe computer or other programmable apparatus provide processes forimplementing the functions/acts specified in the flowchart and/or blockdiagram block or blocks.

A processing system suitable for storing and/or executing program codemay be implemented by any conventional or other computer or processingsystems preferably equipped with a display or monitor, a base (e.g.,including the processor, memories and/or internal or externalcommunications devices (e.g., modem, network cards, etc.) and optionalinput devices (e.g., a keyboard, mouse or other input device)). Thesystem can include at least one processor coupled directly or indirectlyto memory elements through a system bus. The memory elements can includelocal memory employed during actual execution of the program code, bulkstorage, and cache memories which provide temporary storage of at leastsome program code in order to reduce the number of times code must beretrieved from bulk storage during execution. Input/output or I/Odevices (including but not limited to keyboards, displays, pointingdevices, etc.) can be coupled to the system either directly or throughintervening I/O controllers. Network adapters may also be coupled to thesystem to enable the system to become coupled to other processingsystems or remote printers or storage devices through interveningprivate or public networks. Modems, cable modem and Ethernet cards arejust a few of the currently available types of network adapters.

The flowchart and block diagrams in the Figures illustrate thearchitecture, functionality, and operation of possible implementationsof systems, method and computer program products according to variousembodiments of the present invention. In this regard, each block in theflowchart or block diagrams may represent a module, segment, or portionof code, which comprises one or more executable instructions forimplementing the specified logical function(s). It should also be notedthat, in some alternative implementations, the functions noted in theblock may occur out of the order noted in the Figures. For example, twoblocks shown in succession may, in fact, be executed substantiallyconcurrently, or the blocks may sometime be executed in the reverseorder, depending on the functionality involved. It will also be notedthat each block of the block diagrams and/or flowchart illustration, andcombinations of blocks in the block diagrams and/or flowchartillustration, can be implemented by special purpose hardware-basedsystems that perform the specified functions or acts, or combinations ofspecial purpose hardware and computer instructions.

The terminology used herein is for the purpose of describing particularembodiments only and is not intended to be limiting of the invention. Asused herein, the singular forms “a”, “an” and “the” are intended toinclude the plural forms as well, unless the context clearly indicatesotherwise. It will be further understood that the terms “comprises”and/or “comprising,” when used in this specification, specify thepresence of stated features, integers, steps, operations, elements,and/or components, but do not preclude the presence or addition of oneor more features, integers, steps, operations, elements, components,and/or groups thereof.

The corresponding structures, materials, acts, and equivalents of allmeans or step plus function elements in the claims below are intended toinclude any structure, material, or act for performing the function incombination with other claimed elements as specifically claimed. Thedescription of the present invention has been presented for purposes ofillustration and description, but is not intended to be exhaustive orlimited to the invention in the form disclosed. Many modifications andvariations will be apparent to those of ordinary skill in the artwithout departing from the scope and spirit of the invention. Theembodiment was chosen and described in order to best explain theprinciples of the invention and the practical application, and to enableothers of ordinary skill in the art to understand the invention forvarious embodiments with various modifications as are suited to theparticular use contemplated.

What is claimed is:
 1. A computer-implemented method for managing lockson shared resources in a distributed computer system comprising:receiving at a first primary computer node a first local lock state froma first secondary computer node of a plurality of secondary computernodes, wherein the first local lock state provides an amalgamatedrepresentation of lock states of one or more tasks on the firstsecondary computer node and comprises a lock request for access to ashared resource by one or more tasks on the first secondary computernode, a requested lock mode for the lock request, and merged stateinformation of tasks on the first secondary computer node waiting for orholding locks on shared resources, and wherein the merged stateinformation indicates a group lock mode generated by comparing lockmodes of the tasks on the first secondary computer node waiting for orholding locks on the shared resources and identifying a lock modecompatible with each of the lock modes of the tasks as the group lockmode based on the comparing; at the first primary computer node, if thefirst local lock state is not stale, granting the lock request if noconflicts exist, and otherwise adding the first local lock state to apriority queue for the shared resource requested in the lock request andprocessing the priority queue for the shared resource requested in thelock request; at the first primary computer node, generating a firstglobal lock state in response to the first local lock state, wherein thefirst global lock state comprises a holdable lock mode that is grantedto the first secondary computer node for the shared resource requestedin the lock request and merged state information of the plurality ofsecondary computer nodes with respect to the lock request; communicatingthe first global lock state from the first primary computer node to thefirst secondary computer node; at a global deadlock detector, receivingand storing lock conflict information from two or more of the pluralityof secondary computer nodes, wherein for each of the two or moresecondary computer nodes the lock conflict information comprises locallock waits and lock interests for one or more tasks on that secondarycomputer node; at the global deadlock detector, detecting a globaldeadlock using the received lock conflict information, wherein a globaldeadlock is a deadlock between tasks on two or more different ones ofthe plurality of secondary computer nodes; at the global deadlockdetector, resolving the detected global deadlock by selecting one of thedeadlocked tasks as a victim; and communicating the victim selectionfrom the global deadlock detector to the secondary computer node wherethe selected victim task is located.
 2. The method of claim 1, whereinthe priority queue comprises a plurality of client entries, wherein eachclient entry comprises a priority, a local lock state from one of theplurality of secondary computer nodes and a responsive global lock statefrom a corresponding primary computer node, wherein each local lockstate comprises a lock request for access to one of the shared resourcesby one or more tasks on the one secondary computer node and each taskhas an associated lock mode, a fair lock mode that is the associatedlock mode of a top waiter task on the one secondary computer node, aconcurrent lock mode that is the associated lock mode of at least twotasks on the one secondary computer node that are able to runconcurrently if the concurrent lock mode is granted, and a maximum lockmode that is a supremum of the associated lock modes for the one or moretasks on the one secondary computer node, and wherein each responsiveglobal lock state comprises a holdable lock mode indicating a lock modethat was granted to the one secondary computer node, wherein saidprocessing the priority queue comprises: (a) processing fair lock moderequests by, for each individual client entry, granting a lock requestin a fair lock mode for the individual client entry if the fair lockmode of the individual client entry is compatible with both the fairlock mode of all client entries having a higher priority than theindividual client entry and the holdable lock mode of all client entriesin the priority queue; (b) processing concurrent lock mode requests by,for each individual client entry, granting a lock request in aconcurrent lock mode for the individual client entry if the concurrentlock mode of the individual client entry is compatible with both thefair lock mode of all client entries in the priority queue and theholdable lock mode of all client entries in the priority queue; and (c)processing maximum lock mode requests by, for each individual cliententry, granting a lock request in a maximum lock mode for the individualclient entry if the maximum lock mode of the individual client entry iscompatible with both the concurrent lock mode of all client entries inthe priority queue and the holdable lock mode of all client entries inthe priority queue.
 3. The method of claim 2, wherein step (a) furthercomprises, when a fair lock mode request is granted to a client entryfor the one secondary computer node, processing step (b) for otherclient entries of the one secondary computer node before processingsteps (b) or (c) for client entries for other secondary computer nodesof the plurality of secondary computer nodes.
 4. The method of claim 1,wherein each task on the first secondary computer node has an associatedlock mode, the first local lock state further comprises a priority, andthe requested lock mode comprises a fair lock mode that is theassociated lock mode of a top waiter task on the first secondarycomputer node, the method further comprising, at the first primarycomputer node: if the first secondary computer node is waiting for afair lock mode on the shared resource requested in the lock request, andis blocked by a second secondary computer node of the plurality ofsecondary computer nodes holding a lock on the shared resource requestedin the lock request, determining whether the first secondary computernode has a higher priority than the second secondary computer node, andif yes, generating a first lock state notification to the secondsecondary computer node, wherein the first lock state notificationsignals a reclaim of the held lock; and communicating the first lockstate notification from the first primary computer node to the secondsecondary computer node.
 5. The method of claim 1, wherein each task onthe plurality of secondary computer nodes has an associated lock mode,and further comprising, at the first secondary computer node: receivingthe first global lock state; determining whether the first global lockstate is stale, and if yes, discarding the first global lock state; ifsaid determination result is no, then determining whether the firstglobal lock state signals a reclaim of a lock held by the firstsecondary computer node, and if no reclaim is signaled, processing thefirst global lock state by allowing the requesting tasks on the firstsecondary computer node access to the shared resource requested in thelock request according to a lock mode in the first global lock state; ifa reclaim is signaled, then: identifying a current lock mode of the heldlock on the first secondary computer node; identifying one or more taskson the first secondary computer node that are holding or waiting foraccess to the shared resource requested in the lock request and thathave lock modes that are dominated by the current lock mode; allowingthe identified one or more tasks to finish accessing the shared resourcerequested in the lock request; and releasing the held lock to the firstprimary computer node so that the first primary computer node is able togrant said held lock to a remote secondary computer node.
 6. The methodof claim 5, further comprising, at the remote secondary computer node:receiving the held lock from the first primary computer node after saidheld lock has been released by the first secondary computer node;identifying a current lock mode of the held lock on the remote secondarycomputer node; identifying one or more tasks on the remote secondarycomputer node that are holding or waiting for access to the sharedresource requested in the lock request and that have lock modes that aredominated by the current lock mode of the held lock on the remotesecondary computer node; allowing the identified one or more tasks onthe remote secondary computer node to finish accessing the sharedresource requested in the lock request; and releasing the held lock backto the first primary computer node so that the first primary computernode is able to grant said held lock back to the first secondarycomputer node.
 7. The method of claim 1, further comprising, at thefirst secondary computer node: detecting and resolving local deadlocksbetween tasks on the first secondary computer node; detecting that afirst task on the first secondary computer node is blocked by, or isblocking, a second task on a remote secondary computer node; generatinglock conflict information comprising local lock waits for one or moretasks on the first secondary computer node including the first task, andoptionally comprising lock interests for one or more tasks on the firstsecondary computer node, wherein a lock interest identifies a task onthe first secondary computer node waiting for a lock held by a task onthe remote secondary computer node, a task on the first secondarycomputer node holding a lock that is blocking a task on the remotesecondary computer node, or both; and communicating the generated lockconflict information to the global deadlock detector.
 8. The method ofclaim 1, further comprising: at the secondary computer node where theselected victim task is located, receiving the victim selection, andkilling the victim task unless the lock conflict information for thevictim task has changed since it was sent to the global deadlockdetector by the secondary computer node where the selected victim islocated.
 9. A computer-implemented method for managing locks on sharedresources in a distributed computer system comprising: receiving at afirst primary computer node a first local lock state from a firstsecondary computer node of a plurality of secondary computer nodes,wherein the first local lock state provides an amalgamatedrepresentation of lock states of one or more tasks on the firstsecondary computer node and comprises a lock request for access to ashared resource by one or more tasks on the first secondary computernode, a requested lock mode for the lock request, and merged stateinformation of tasks on the first secondary computer node waiting for orholding locks on shared resources, and wherein the merged stateinformation indicates a group lock mode generated by comparing lockmodes of the tasks on the first secondary computer node waiting for orholding locks on the shared resources and identifying a lock modecompatible with each of the lock modes of the tasks as the group lockmode based on the comparing; at the first primary computer node, if thefirst local lock state is not stale, granting the lock request if noconflicts exist, and otherwise adding the first local lock state to apriority queue for the shared resource requested in the lock request andprocessing the priority queue for the shared resource requested in thelock request; at the first primary computer node, generating a firstglobal lock state in response to the first local lock state, wherein thefirst global lock state comprises a holdable lock mode that is grantedto the first secondary computer node for the shared resource requestedin the lock request and merged state information of the plurality ofsecondary computer nodes with respect to the lock request; communicatingthe first global lock state from the first primary computer node to thefirst secondary computer node; at the first secondary computer node:receiving the first global lock state; determining whether the firstglobal lock state is stale, and if yes, discarding the first global lockstate; if said determination result is no, then determining whether thefirst global lock state signals a reclaim of a lock held by the firstsecondary computer node, and if no reclaim is signaled, processing thefirst global lock state by allowing the requesting tasks on the firstsecondary computer node access to the shared resource requested in thelock request according to the holdable lock mode in the first globallock state; in response to the first global lock state signaling areclaim of a lock held by the first secondary computer node: identifyinga current lock mode of the held lock on the first secondary computernode and one or more tasks on the first secondary computer node that areholding or waiting for access to the shared resource requested in thelock request and that have lock modes that are dominated by the currentlock mode; and allowing the identified one or more tasks to finishaccessing the shared resource requested in the lock request andreleasing the held lock to the first primary computer node so that thefirst primary computer node is able to grant said held lock to a remotesecondary computer node.
 10. The method of claim 9, further comprising,at the remote secondary computer node: receiving the held lock from thefirst primary computer node after said held lock has been released bythe first secondary computer node; identifying a current lock mode ofthe held lock on the remote secondary computer node; identifying one ormore tasks on the remote secondary computer node that are holding orwaiting for access to the shared resource requested in the lock requestand that have lock modes that are dominated by the current lock mode ofthe held lock on the remote secondary computer node; allowing theidentified one or more tasks on the remote secondary computer node tofinish accessing the shared resource requested in the lock request; andreleasing the held lock back to the first primary computer node so thatthe first primary computer node is able to grant said held lock back tothe first secondary computer node.